//页面gui
var objScreen = {};

$(function () {
    $.parser.parse(); // 解析整个页面
    //年
    $('#qcYear').combobox({
        data: $.parseJSON($("#yearMap").val()),
        valueField: 'value',
        textField: 'text',
        defaultFilter: 6,
        onLoadSuccess: function () { //加载完成后,val[0]写死设置选中第一项
            var val = $(this).combobox("getData");
            $(this).combobox("setValue", val[0].value);
        }
        //onSelect:ManageIndex.departChange
    });
    // 是否启用首页总体情况统计
    if ($("#enableGeneralInfo").val() == 'Y') {
        //上报总体情况
        objScreen.initMrlistCnt();
        //近一年单病种上报情况
        objScreen.drawMainChart();
        //科室上报情况
        objScreen.refLocSum();
        //十日上报及时率
        objScreen.reportInTimeRate();
    }
    // 是否启用首页病种填写情况
    if ($("#enableDisFillingInfo").val() == 'Y') {
        // 病种自动填报率
        objScreen.refARatio();
        // 病种填报用时分析
        objScreen.qcUseTime();
    }
    /* 病种开展情况
     objScreen.refQCOpenSum();
     加载各疾病系统费用 住院日情况
     objScreen.refQCSysSum();*/

    // 如果开启过程质控模块
    if ($("#enableIPQC").val() == 'Y') {
        //病种质控统计
        objScreen.qcDisSta();
        //科室质控统计
        objScreen.qcDeptSta();
        //过程质控触发趋势统计
        objScreen.qcTrigger();
        //过程质控医生统计
        objScreen.qcDocSta();
    }
    // 是否启用首页【病种上报统计】情况
    if ($("#enableDisReportInfo").val() == 'Y') {
        //病种上报情况
        objScreen.refQCSum();
        //医生上报情况
        objScreen.refDocSum();
    }
    //科室
    $('#depart').combobox({
        data: $.parseJSON($("#departMap").val()),
        valueField: 'value',
        textField: 'text',
        defaultFilter: 6
        //onSelect:ManageIndex.departChange
    });
    //院区
    $('#office').combobox({
        data: $.parseJSON($("#officeMap").val()),
        valueField: 'value',
        textField: 'text',
        defaultFilter: 6,
        onSelect: objScreen.officeChange,
        onLoadSuccess: function () { //加载完成后,val[0]写死设置选中第一项
            var val = $(this).combobox("getData");
            if (val.length == 2) {//如果就一个院区 加上全部=2
                $(this).combobox("setValue", val[1].value);
                objScreen.officeChange(val[1]);
                $("#oneOffice").val("yes");
            } else {
                $(this).combobox("setValue", "");
                $("#oneOffice").val("no");
            }
        }
    });
    //病种
    $('#qcEntity').combobox({
        data: $.parseJSON($("#entityMap").val()),
        valueField: 'value',
        textField: 'text',
        defaultFilter: 6
        //onSelect:ManageIndex.departChange
    });
    //月
    $('#qcMonth').combobox({
        data: $.parseJSON($("#monthMap").val()),
        valueField: 'value',
        textField: 'text',
        defaultFilter: 6
        //onSelect:ManageIndex.departChange
    });
});

objScreen.officeChange = function (that) {
    var ajax = new $ax(Sys.backendPath + "/sds/common/deptListByHospId", function (data) {
        $('#depart').combobox({
            data: data,
            valueField: 'value',
            textField: 'text',
            defaultFilter: 6,
            onLoadSuccess: function () { //加载完成后,val[0]写死设置选中第一项
                $(this).combobox("setValue", "");
            }
        });
    }, function (data) {
        layer.msg("查询失败!" + data.responseJSON.message + "!", {icon: 2});
    });
    ajax.set({"hospID": that.value, "id": "depart"});
    ajax.start();
}


$('.index-value').on('click', function () {
    var idName = $(this).attr('id');
    var index = Sys.open_c('关注病例列表', '/analysis/qcportal/detailslist?idName=' + idName, null, function () {
    });
    this.layerIndex = index;
});
$('#disHasDev').on('click', function () {
    var index = Sys.open_c('已开展病种列表', '/analysis/qcportal/devlistofdis', ['60%', '60%'], function () {
    });
    this.layerIndex = index;
});


$('#delayReport').on('click', function () {
    var index = Sys.open_c('迟报', '/analysis/qcportal/delayReport', ['80%', '80%'], function () {
    });
    this.layerIndex = index;
})

$('.more-oper').on('click', function () {
    if ($(this).attr('id') == 'qcUseTime-More') {//病种填报用时情况
        objScreen.showUseTimeAlias();
    } else if ($(this).attr('id') == 'qcCategory-More') {//病种质控统计详细页面
        objScreen.showDisTrSta();
    } else if ($(this).attr('id') == "QCSumMore") {
        var idName = $(this).attr('id');
        var qcTimeDimens = $("input[name='QCRido']:checked").val();
        var index = Sys.open_c('关注病例列表', '/analysis/portal/list?idName=' + idName + '&qcTimeDimens=' + qcTimeDimens, null, function () {
        });
        this.layerIndex = index;
    } else if ($(this).attr('id') == "LocSumMore") {
        var idName = $(this).attr('id');
        var qcTimeDimens = $("input[name='LocRido']:checked").val();
        var index = Sys.open_c('关注病例列表', '/analysis/portal/list?idName=' + idName + '&qcTimeDimens=' + qcTimeDimens, null, function () {
        });
        this.layerIndex = index;
    } else if ($(this).attr('id') == "DocSumMore") {
        var idName = $(this).attr('id');
        var qcTimeDimens = $("input[name='DocRido']:checked").val();
        var index = Sys.open_c('关注病例列表', '/analysis/portal/list?idName=' + idName + '&qcTimeDimens=' + qcTimeDimens, null, function () {
        });
        this.layerIndex = index;
    } else if ($(this).attr('id') == 'refARatio-More') {//病种自动提取率情况
        objScreen.showRefARatio();
    } else if ($(this).attr('id') == 'qcDoc-More') {//医生质控统计详细
        objScreen.showDocTrSta();
    } else if ($(this).attr('id') == "upTimeEntityMore") { // 十日填报率
        objScreen.showReportInTimeDetails();
    }
});


objScreen.showUseTimeAlias = function () {
    var index = Sys.open_c('病种填报用时分析', '/analysis/qcportal/useTime', null, function () {
    });
    this.layerIndex = index;
}

objScreen.showDisTrSta = function () {
    var index = Sys.open_c('病种质控触发统计', '/analysis/qcportal/distrsta', ['80%', '80%'], function () {
    });
    this.layerIndex = index;
}

objScreen.showDocTrSta = function () {
    var index = Sys.open_c('医生统计详情', '/analysis/qcportal/doctrsta', ['80%', '80%'], function () {
    });
    this.layerIndex = index;
}

objScreen.showRefARatio = function () {
    var index = Sys.open_c('病种自动填充率分析', '/analysis/qcportal/refARatio', null, function () {
    });
    this.layerIndex = index;
}

objScreen.showReportInTimeDetails = function () {
    var index = Sys.open_c('病种十日填报率', '/analysis/qcportal/reportInTime', null, function () {
    });
    this.layerIndex = index;
}


objScreen.initMrlistCnt = function () {
    var params = {};
    var ajax = new $ax(Sys.backendPath + "/analysis/qcportal/buildRepInfo", function (data) {
        $('#todayRep').html(data.todayRep);
        $('#monthRep').html(data.monthRep);
        $('#quarterRep').html(data.quarterRep);
        $('#yearRep').html(data.yearRep);
        $('#totalRep').html(data.totalRep)


        $('#todayOPRep').html(data.todayOPRep)
        $('#todayIPRep').html(data.todayIPRep)
        $('#preDayRepRatio').html(data.preDayRepRatio)
        $('#overDayRepRatio').html(data.overDayRepRatio);

        $('#monthOPRep').html(data.monthOPRep)
        $('#monthIPRep').html(data.monthIPRep)
        $('#preMonthRepRatio').html(data.preMonthRepRatio)
        $('#overMonthRepRatio').html(data.overMonthRepRatio)

        $('#preQuarterRepRatio').html(data.preQuarterRepRatio)
        $('#overQuarterRepRatio').html(data.overQuarterRepRatio)

        $('#yearOPRep').html(data.yearOPRep)
        $('#yearIPRep').html(data.yearIPRep)
        $('#preYearRepRatio').html(data.preYearRepRatio)
        $('#totalOPRep').html(data.totalOPRep)
        $('#totalIPRep').html(data.totalIPRep)
        $('#disHasDev').html(data.disHasDev)
        $('#delayReport').html(data.delayReport)
    }, function (data) {
    });
    ajax.set(params);
    ajax.start();
}

objScreen.drawMainChart = function () {
    var xdata = [];
    var ydata = [];
    var params = {};
    var ajax = new $ax(Sys.backendPath + "/analysis/qcportal/selectNearYearRep", function (data) {
        var res = data.mainChart
        for (let i in res) {
            xdata.push(i);
            ydata.push(res[i]);
        }
        var myChart = echarts.init(document.getElementById('lastYear'));
        // 指定图表的配置项和数据
        var option = {
            title: {
                text: '近一年上报情况'
            },
            tooltip: {},
            legend: {},
            xAxis: {
                data: xdata,
                axisLine: {
                    lineStyle: {}
                }
            },
            yAxis: {},
            series: [
                {
                    name: '例数',
                    type: 'line',
                    smooth: true,
                    showAllSymbol: true,
                    symbol: 'emptyCircle',
                    symbolSize: 15,
                    data: ydata,
                    markLine: {
                        data: [{type: 'average', name: '月均上报'}]
                    },
                    label: {
                        show: true, // 显示标签
                        position: 'top' // 标签位置顶部
                    }
                },

            ]
        };
        myChart.setOption(option);
        $("#downloadLastYear").on('click', function () {
            objScreen.downloadEcharts(option, myChart);
        });
    }, function (data) {
    });
    ajax.set(params);
    ajax.start();
}

// objScreen.refQCOpenSum = function(){
//     var dataobj = []
//     var params = {};
//     var ajax = new $ax(Sys.backendPath + "/analysis/qcportal/selectQCOpenSum", function (data) {
//         var res = data.openSum
//         for(let i in res){
//             var tobj = new Object()
//             tobj.name = i
//             tobj.value = res[i]
//             dataobj.push(tobj)
//         }
//         var myChart = echarts.init(document.getElementById('QCOpenSum'));
//         // 指定图表的配置项和数据
//         var option = {
//             title: {
//                 text: '病种开展情况',
//             },
//             tooltip: {
//                 trigger: 'item'
//             },
//             legend: {
//                 orient: 'vertical',
//                 left: 'right'
//             },
//             series: [
//                 {
//                     name: '上报病种情况',
//                     type: 'pie',
//                     label: {
//                         show: false
//                     },
//                     data: dataobj
//                 }
//             ]
//         };
//         myChart.setOption(option);
//     }, function (data){
//     });
//     ajax.set(params);
//     ajax.start();
// }

// objScreen.refQCSysSum = function(){
//     //疾病系统费用展现
//     var params = {};
//     var ajax = new $ax(Sys.backendPath + "/analysis/qcportal/selectQCSysInfo", function (data) {
//         var xdata = []
//         var ydata = []
//         var dataArr = data.fees
//         var datalen = dataArr.length
//         for (var i = 0; i < datalen; i++) {
//             var row = dataArr[i]
//             xdata.push(row.description);
//             ydata.push(row.averageHospCosts);
//         }
//         var myChart = echarts.init(document.getElementById('CostInfo'));
//         // 指定图表的配置项和数据
//         var option = {
//             title: {
//                 text: '疾病费用'
//             },
//             tooltip: {
//                 formatter: '{b}<br/>平均住院费用：' + '{c}'
//             },
//             legend: {},
//             xAxis: {
//                 data: xdata
//             },
//             yAxis: {},
//             series: [
//                 {
//                     name: '平均费用',
//                     type: 'bar',
//                     data: ydata,
//                     barMaxWidth:'40px',
//                     itemStyle: {
//                         borderRadius: 5,
//                         color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
//                             { offset: 0, color: '#83bff6' },
//                             { offset: 0.5, color: '#188df0' },
//                             { offset: 1, color: '#188df0' }
//                         ])
//                     },
//                 }
//             ]
//         };
//         myChart.setOption(option);
//
//         //疾病系统住院日展现
//         var xdata = []
//         var ydata = []
//         var dataArr = data.days
//         var datalen = dataArr.length
//         for (var i = 0; i < datalen; i++) {
//             var row = dataArr[i]
//             xdata.push(row.description);
//             ydata.push(row.averageDays);
//         }
//         var myChart = echarts.init(document.getElementById('IndaysInfo'));
//         // 指定图表的配置项和数据
//         var option = {
//             title: {
//                 text: '住院天数'
//             },
//             tooltip: {
//                 formatter: '{b}<br/>平均住院日：' + '{c}'
//             },
//             legend: {},
//             xAxis: {
//                 type: 'category',
//                 data: xdata
//             },
//             yAxis: {
//                 type: 'value'
//             },
//             series: [
//                 {
//                     name: '平均住院天数',
//                     type: 'bar',
//                     data: ydata,
//                     barMaxWidth:'40px',
//                     itemStyle: {
//                         borderRadius: 5,
//                         color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
//                             { offset: 0, color: '#83bff6' },
//                             { offset: 0.5, color: '#188df0' },
//                             { offset: 1, color: '#188df0' }
//                         ])
//                     },
//                 }
//             ]
//         };
//         myChart.setOption(option);
//     }, function (data){
//     });
//     ajax.set(params);
//     ajax.start();
//
//     //疾病系统费用展现
//     /*var params = {};
//     var ajax = new $ax(Sys.backendPath + "/analysis/portal/selectSysSumChart", function (data) {
//         var xdata = []
//         var ydata = []
//         var dataArr = data.averageData
//         var datalen = dataArr.length
//         for (var i = 0; i < datalen; i++) {
//             var row = dataArr[i]
//             xdata.push(row.description);
//             ydata.push(row.averageCosts);
//         }
//         var myChart = echarts.init(document.getElementById('CostInfo'));
//         // 指定图表的配置项和数据
//         var option = {
//             title: {
//                 text: '疾病费用'
//             },
//             tooltip: {
//                 formatter: '{b}<br/>平均住院费用：' + '{c}'
//             },
//             legend: {},
//             xAxis: {
//                 data: xdata
//             },
//             yAxis: {},
//             series: [
//                 {
//                     name: '平均费用',
//                     type: 'bar',
//                     data: ydata,
//                     barMaxWidth:'40px',
//                     itemStyle: {
//                         borderRadius: 5,
//                         color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
//                             { offset: 0, color: '#83bff6' },
//                             { offset: 0.5, color: '#188df0' },
//                             { offset: 1, color: '#188df0' }
//                         ])
//                     },
//                 }
//             ]
//         };
//         myChart.setOption(option);
//
//         //疾病系统住院日展现
//         var xdata = []
//         var ydata = []
//         for (var i = 0; i < datalen; i++) {
//             var row = dataArr[i]
//             xdata.push(row.description);
//             ydata.push(row.averageDays);
//         }
//         var myChart = echarts.init(document.getElementById('IndaysInfo'));
//         // 指定图表的配置项和数据
//         var option = {
//             title: {
//                 text: '住院天数'
//             },
//             tooltip: {
//                 formatter: '{b}<br/>平均住院日：' + '{c}'
//             },
//             legend: {},
//             xAxis: {
//                 type: 'category',
//                 data: xdata
//             },
//             yAxis: {
//                 type: 'value'
//             },
//             series: [
//                 {
//                     name: '平均住院天数',
//                     type: 'bar',
//                     data: ydata,
//                     barMaxWidth:'40px',
//                     itemStyle: {
//                         borderRadius: 5,
//                         color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
//                             { offset: 0, color: '#83bff6' },
//                             { offset: 0.5, color: '#188df0' },
//                             { offset: 1, color: '#188df0' }
//                         ])
//                     },
//                 }
//             ]
//         };
//         myChart.setOption(option);
//     }, function (data){
//     });
//     ajax.set(params);
//     ajax.start();*/
// }

objScreen.refQCSum = function(){
    var params = {};
    var ajax = new $ax(Sys.backendPath + "/analysis/qcportal/selectQCUpLoadData", function (data) {
        var dataArr = data.upEntitys
        var datalen = dataArr.length
        var dataobj = []
        for (var i = 0; i < datalen; i++) {
            var row = dataArr[i]
            var tobj = new Object()
            tobj.value = row.count
            tobj.name = row.code
            dataobj.push(tobj)
        }
        dataobj.sort(function(a, b){return b.value - a.value});
        dataobj=dataobj.slice(0,10);
        var myChart = echarts.init(document.getElementById('QCSum'));
        // 指定图表的配置项和数据
        var option = {
            title: {
                text: '病种上报情况',
            },
            tooltip: {
                trigger: 'item'
            },
            legend: {
                orient: 'vertical',
                left: 'right'
            },
            series: [
                {
                    name: '上报例数',
                    type: 'pie',
                    radius:[70,100],
                    // roseType: 'area',
                    itemStyle: {
                        borderRadius: 5
                    },
                    label: {
                        show: false
                    },
                    data: dataobj
                }
            ]
        };
        myChart.setOption(option);
    }, function (data){
    });
    params.qcTimeDimens = $("input[name='QCRido']:checked").val();
    ajax.set(params);
    ajax.start();
}


objScreen.reportInTimeRate = function () {
    var params = {};
    var ajax = new $ax(Sys.backendPath + "/analysis/sdsmsta2/selectSdsUpData", function (data) {
        objScreen.drawMiddleChart(data.upTimeEntityData);
    }, function (data) {
    });
    params.qcTimeDimens = $("input[name='UpTimeRido']:checked").val();
    ajax.set(params);
    ajax.set(params);
    ajax.start();
}
objScreen.drawMiddleChart = function (data) {
    var dataArr = data
    var datalen = dataArr.length
    var dataobj = []
    for (var i = 0; i < datalen; i++) {
        var row = dataArr[i]
        var tobj = new Object()
        tobj.value = row.aRatio
        tobj.name = row.entityDesc
        dataobj.push(tobj)
    }
    dataobj.sort(function(a, b){return b.value - a.value});
    // dataobj = dataobj.slice(0, 10);
    var xdata = []
    var ydata = []
    dataobj.forEach(function (item, index) {
        xdata.push(item.name);
        ydata.push(item.value);
    });
    var myChart = echarts.init(document.getElementById('upTimeEntityChart'));
    // 指定图表的配置项和数据
    var option = {
        title: {
            text: '十日填报率',
        },
        tooltip: {
            trigger: "axis"
        },
        legend: {},
        xAxis: {
            type: 'category',
            data: xdata,
            axisLabel: {
                interval: 0,
                formatter: function (params) {
                    var str = "";                 // 最终拼接成的字符串
                    var paramsLen = params.length;// 获取每项文字的个数
                    var len = 4;                  // 每行能显示的字的个数（根据实际情况自己设置）
                    var rowNumber = Math.ceil(paramsLen / len); // 换行的话，需要显示几行，向上取整
                    if (paramsLen > len) {        //大于设定的len就换行，不大于就不变化
                        for (var i = 0; i < rowNumber; i++) {
                            var temp = "";            // 表示每一次截取的字符串
                            var start = i * len;      // 开始截取的位置
                            var end = start + len;    // 结束截取的位置
                            if (i == rowNumber - 1) { // 最后一次不换行
                                temp = params.substring(start, paramsLen);
                            } else {                  // 每一次拼接字符串并换行
                                temp = params.substring(start, end) + "\n";
                            }
                            str += temp;              // 最终拼成的字符串
                        }
                    } else {                      // 给新的字符串赋值
                        str = params;
                    }
                    return str;                   //返回字符串
                }
            }
        },
        yAxis: {
            type: 'value',
            name: "%",
            max: 'dataMax'
        },
        series: [
            {
                type: 'bar',
                data: ydata,
                // realtimeSort: true,
                // showBackground: true,
                barMaxWidth: '40px',
                itemStyle: {
                    color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                        {offset: 0, color: '#83bff6'},
                        {offset: 0.5, color: '#188df0'},
                        {offset: 1, color: '#188df0'}
                    ])
                },
                label: {
                    show: true, // 显示标签
                    position: 'top' // 标签位置顶部
                }
            }
        ],
        dataZoom: [{
            type:'slider',
            xAxisIndex: [0],
            start: 0,
            end:20
        }],
        grid:{
            containLabel: true, //注意加上，否则axisLabel有可能显示会不全
            bottom:"30px"
        }
    };
    myChart.setOption(option);
    $("#downloadUpTimeEntity").on('click', function () {
        objScreen.downloadEcharts(option);
    });
};

objScreen.refLocSum = function () {
    var params = {};
    var ajax = new $ax(Sys.backendPath + "/analysis/qcportal/selectLocUpLoadData", function (data) {
        var dataArr = data.upLoc
        var datalen = dataArr.length
        var dataobj = []
        for (var i = 0; i < datalen; i++) {
            var row = dataArr[i]
            var tobj = new Object()
            tobj.value = row.count
            tobj.name = row.description
            dataobj.push(tobj)
        }
        dataobj.sort(function (a, b) {
            return b.value - a.value
        });
        // dataobj = dataobj.slice(0, 10);

        var xdata = []
        var ydata = []
        dataobj.forEach(function (item, index) {
            xdata.push(item.name);
            ydata.push(item.value);
        });

        var myChart = echarts.init(document.getElementById('LocSum'));
        var option = {
            color: ['#2EB7BD', '#3CE1D9', '#FBBACB', '#4695D1'],
            title: {
                text: '科室上报情况'
            },
            tooltip: {},
            legend: {},
            xAxis: {
                type: 'category',
                data: xdata,
                axisLabel: {
                    interval: 0,
                    formatter: function (params) {
                        var str = "";                 // 最终拼接成的字符串
                        var paramsLen = params.length;// 获取每项文字的个数
                        var len = 4;                  // 每行能显示的字的个数（根据实际情况自己设置）
                        var rowNumber = Math.ceil(paramsLen / len); // 换行的话，需要显示几行，向上取整
                        if (paramsLen > len) {        //大于设定的len就换行，不大于就不变化
                            for (var i = 0; i < rowNumber; i++) {
                                var temp = "";            // 表示每一次截取的字符串
                                var start = i * len;      // 开始截取的位置
                                var end = start + len;    // 结束截取的位置
                                if (i == rowNumber - 1) { // 最后一次不换行
                                    temp = params.substring(start, paramsLen);
                                } else {                  // 每一次拼接字符串并换行
                                    temp = params.substring(start, end) + "\n";
                                }
                                str += temp;              // 最终拼成的字符串
                            }
                        } else {                      // 给新的字符串赋值
                            str = params;
                        }
                        return str;                   //返回字符串
                    }
                }
            },
            yAxis: {
                type: 'value',
                name: '例',
                splitLine: {
                    show: true,
                    lineStyle: {
                        color: '#cccccc'
                    }
                }
            },
            series: [{
                name: "",
                type: "bar",
                itemStyle: {
                    normal: {
                        color: function (params) {
                            var index = params.dataIndex
                            //注意，如果颜色太少的话，后面颜色不会自动循环，最好多定义几个颜色
                            var colorList = ['#5470C6', '#FAC858', '#91CC75', '#c23531', '#2f4554', '#61a0a8', '#d48265', '#91c7ae', '#749f83', '#ca8622'];
                            // if (params.dataIndex >= colorList.length) {
                            //     index = params.dataIndex - colorList.length;
                            // }
                            index = params.dataIndex % colorList.length;
                            return colorList[index]
                        }
                    }
                },
                data: ydata,
                label: {
                    show: true, // 显示标签
                    position: 'top' // 标签位置顶部
                }
            }],
            dataZoom: [{
                type:'slider',
                xAxisIndex: [0],
                start: 0,
                end:30
            }],
            grid:{
                containLabel: true,
                bottom:"30px"
            }
        };
        myChart.setOption(option);
        $("#downloadLocSum").on('click', function () {
            objScreen.downloadEcharts(option);
        });
    }, function (data) {
    });
    params.qcTimeDimens = $("input[name='LocRido']:checked").val();
    ajax.set(params);
    ajax.start();

}

objScreen.refDocSum = function () {
    var params = {};
    var ajax = new $ax(Sys.backendPath + "/analysis/qcportal/selectDocUpLoadData", function (data) {
        var dataArr = data.upDoc
        var datalen = dataArr.length
        var dataobj = []
        for (var i = 0; i < datalen; i++) {
            var row = dataArr[i]
            var tobj = new Object()
            tobj.value = row.count
            tobj.name = row.description
            dataobj.push(tobj)
        }
        dataobj.sort(function (a, b) {
            return b.value - a.value
        });
        dataobj = dataobj.slice(0, 10);
        var myChart = echarts.init(document.getElementById('DocSum'));
        var option = {
            title: {
                text: '医生上报情况'
            },
            tooltip: {},
            legend: {
                orient: 'vertical',
                left: 'right'
            },
            series: [
                {
                    type: 'pie',
                    data: dataobj,
                    label: {
                        show: false
                    },
                }
            ]
        };
        myChart.setOption(option);
    }, function (data) {
    });
    params.qcTimeDimens = $("input[name='DocRido']:checked").val();
    ajax.set(params);
    ajax.start();
}

objScreen.qcDisSta = function () {
    var params = {};
    var ajax = new $ax(Sys.backendPath + "/analysis/qcportal/selectQCCategory", function (data) {
        var dataArr = data.qcCategory
        var datalen = dataArr.length
        var dataobj = []
        for (var i = 0; i < datalen; i++) {
            var row = dataArr[i]
            var tobj = new Object()
            tobj.value = row.count
            tobj.name = row.patName
            tobj.id = row.ids
            tobj.description = row.description
            dataobj.push(tobj)
        }
        //var sortflg = $("input[name='AutoRatio']:checked").val();
        dataobj = dataobj.slice(0, 10);
        var xdata = []
        var ydata = []
        dataobj.forEach(function (item, index) {
            xdata.push(item.name);
            ydata.push(item.value);
        });
        var myChart = echarts.init(document.getElementById('qcCategory'));
        // 指定图表的配置项和数据
        var option = {
            title: {
                text: '病种质控统计',
                left: 'center'
            },
            tooltip: {
                trigger: 'item'
            },
            legend: {
                orient: 'vertical',
                left: 'left'
            },
            series: [
                {
                    name: '病种触发数',
                    radius: '115px',
                    type: 'pie',
                    data: dataobj,
                    emphasis: {
                        itemStyle: {
                            shadowBlur: 10,
                            shadowOffsetX: 0,
                            shadowColor: 'rgba(0, 0, 0, 0.5)'
                        }
                    },
                    barMaxWidth: '40px',
                }
            ]
        };
        myChart.setOption(option);
        myChart.on('click', function (params) {
            objScreen.qcDetail(encodeURIComponent(params.data.id), encodeURIComponent(params.data.description));
        })
    }, function (data) {
    });
    ajax.set(params);
    ajax.start();
}
objScreen.qcDetail = function (id, qcDisName) {

    var index = Sys.open_c('质控项触发统计', '/analysis/qcportal/qcDetail?id=' + id + '&qcDisName=' + qcDisName, ['80%', '80%'], function () {
    });
    this.layerIndex = index;
}

objScreen.qcTrigger = function () {
    var xdata=[];
    var ydata=[];
    var params = {};
    var ajax = new $ax(Sys.backendPath + "/analysis/qcportal/selectTriggerCountByDate", function (data) {
        var dataArr = data.triggerChart
        var datalen = dataArr.length
        for (var i = 0; i < datalen; i++) {
            var row = dataArr[i]
            xdata.push(row.date);
            ydata.push(row.count);
        }
        var myChart = echarts.init(document.getElementById('qcTrigger'));
        // 指定图表的配置项和数据
        var option = {
            title: {
                text: '过程质控触发趋势'
            },
            tooltip: {},
            legend: {},
            xAxis: {
                data: xdata,
                axisLine: {
                    lineStyle: {

                    }
                }
            },
            yAxis: {},
            series: [
                {
                    name: '触发人次数',
                    type: 'line',
                    smooth: true,
                    showAllSymbol: true,
                    symbol: 'emptyCircle',
                    symbolSize: 15,
                    data: ydata,
                    markLine: {
                        data: [{ type: 'average', name: '月均人次' }]
                    }
                },
            ]
        };
        myChart.setOption(option);
    },function (data){
    });
    ajax.set(params);
    ajax.start();
}

objScreen.qcDocSta = function () {
    var params = {};
    var ajax = new $ax(Sys.backendPath + "/analysis/qcportal/selectDoctorChartData", function (data) {
        var dataArr = data.doctorChart
        var datalen = dataArr.length
        var dataobj = []
        for (var i = 0; i < datalen; i++) {
            var row = dataArr[i]
            var tobj = new Object()
            tobj.value = row.count
            tobj.name = row.docName
            dataobj.push(tobj)
        }
        var xdata = [], ydata = []
        dataobj.forEach(function (item, index) {
            xdata.push(item.name);
            ydata.push(item.value);
        });
        var myChart = echarts.init(document.getElementById('qcDoc'));
        // 指定图表的配置项和数据
        var option = {
            title: {
                text: '医生统计'
            },
            tooltip: {},
            legend: {},
            xAxis: {
                type: 'value'
            },
            yAxis: {
                type: 'category',
                data: xdata
            },
            series: [
                {
                    type: 'bar',
                    data: ydata,
                    itemStyle: {
                        color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                            {offset: 0, color: '#83bff6'},
                            {offset: 0.5, color: '#188df0'},
                            {offset: 1, color: '#188df0'}
                        ])
                    },
                },

            ]
        };
        myChart.setOption(option);
    }, function (data) {
    });
    ajax.set(params);
    ajax.start();
}


objScreen.qcDeptSta = function (sortflg) {
    var params = {};
    var ajax = new $ax(Sys.backendPath + "/analysis/qcportal/selectQCDept", function (data) {
        var dataArr = data.qcDept
        var datalen = dataArr.length
        var dataobj = []
        for (var i = 0; i < datalen; i++) {
            var row = dataArr[i]
            var tobj = new Object()
            tobj.value = row.deptCount
            tobj.name = row.deptName
            dataobj.push(tobj)
        }
        if (sortflg == "DESC") {
            dataobj.sort(function (a, b) {
                return b.value - a.value
            });
        } else {
            dataobj.sort(function (a, b) {
                return a.value - b.value
            });
        }
        dataobj = dataobj.slice(0, 10);
        var xdata = [], ydata = []
        dataobj.forEach(function (item, index) {
            xdata.push(item.name);
            ydata.push(item.value);
        });
        var myChart = echarts.init(document.getElementById('qcDept'));
        // 指定图表的配置项和数据
        var option = {
            title: {
                text: '科室质控统计',
                left: 'center'
            },
            tooltip: {},
            legend: {},
            xAxis: {
                type: 'category',
                data: xdata
            },
            yAxis: {
                max: 'dataMax'
            },
            series: [
                {
                    type: 'bar',
                    data: ydata,
                    barMaxWidth: '40px',
                    itemStyle: {
                        color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                            {offset: 0, color: '#83bff6'},
                            {offset: 0.5, color: '#188df0'},
                            {offset: 1, color: '#188df0'}
                        ])
                    },
                }
            ]
        };
        myChart.setOption(option);
    }, function (data) {
    });
    ajax.set(params);
    ajax.start();
}


objScreen.refARatio = function (sortflg) {
    var params = {};
    var ajax = new $ax(Sys.backendPath + "/analysis/qcportal/selectQCARatio", function (data) {
        var dataArr = data.aRatioData
        var datalen = dataArr.length
        var dataobj = []
        for (var i = 0; i < datalen; i++) {
            var row = dataArr[i]
            var tobj = new Object()
            tobj.value = row.aRatio
            tobj.name = row.code;
            dataobj.push(tobj)
        }
        if (sortflg == "ASC") {
            dataobj.sort(function (a, b) {
                return a.value - b.value
            });
        } else {
            dataobj.sort(function (a, b) {
                return b.value - a.value
            });
        }
        // dataobj = dataobj.slice(0, 10);
        var xdata = [], ydata = []
        dataobj.forEach(function (item, index) {
            xdata.push(item.name);
            ydata.push(item.value);
        });
        var myChart = echarts.init(document.getElementById('refARatio'));
        // 指定图表的配置项和数据
        var option = {
            title: {
                text: '病种自动填报率分析',
                left: 'center'
            },
            tooltip: {},
            legend: {},
            xAxis: {
                type: 'category',
                data: xdata,
                axisLabel: {
                    interval: 0,
                    formatter: function (params) {
                        var str = "";                 // 最终拼接成的字符串
                        var paramsLen = params.length;// 获取每项文字的个数
                        var len = 5;                  // 每行能显示的字的个数（根据实际情况自己设置）
                        var rowNumber = Math.ceil(paramsLen / len); // 换行的话，需要显示几行，向上取整
                        if (paramsLen > len) {        //大于设定的len就换行，不大于就不变化
                            for (var i = 0; i < rowNumber; i++) {
                                var temp = "";            // 表示每一次截取的字符串
                                var start = i * len;      // 开始截取的位置
                                var end = start + len;    // 结束截取的位置
                                if (i == rowNumber - 1) { // 最后一次不换行
                                    temp = params.substring(start, paramsLen);
                                } else {                  // 每一次拼接字符串并换行
                                    temp = params.substring(start, end) + "\n";
                                }
                                str += temp;              // 最终拼成的字符串
                            }
                        } else {                      // 给新的字符串赋值
                            str = params;
                        }
                        return str;                   //返回字符串
                    }
                }
            },
            yAxis: {
                name: '%',
                max: 'dataMax'
            },
            series: [
                {
                    type: 'bar',
                    data: ydata,
                    barMaxWidth: '40px',
                    itemStyle: {
                        color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                            {offset: 0, color: '#83bff6'},
                            {offset: 0.5, color: '#188df0'},
                            {offset: 1, color: '#188df0'}
                        ])
                    },
                    label: {
                        show: true, // 显示标签
                        position: 'top' // 标签位置顶部
                    }
                }
            ],
            dataZoom: [{
                type:'slider',
                xAxisIndex: [0],
                start: 0,
                end:30
            }]
        };
        myChart.setOption(option);
        $("#downloadRefARatio").on('click', function () {
            objScreen.downloadEcharts(option);
        });
    }, function (data) {
    });
    ajax.set(params);
    ajax.start();
}

objScreen.qcUseTime = function (sortflg) {
    var params = {};
    var ajax = new $ax(Sys.backendPath + "/analysis/qcportal/selectQCUseTime", function (data) {
        var dataArr = data.useTimeData
        var datalen = dataArr.length
        var dataobj = []
        for (var i = 0; i < datalen; i++) {
            var row = dataArr[i]
            var tobj = new Object()
            tobj.value = row.avgUseTime
            tobj.name = row.code;
            dataobj.push(tobj)
        }
        if (sortflg == "DESC") {
            dataobj.sort(function (a, b) {
                return b.value - a.value
            });
        } else {
            dataobj.sort(function (a, b) {
                return a.value - b.value
            });
        }
        // dataobj = dataobj.slice(0, 10);
        var xdata = [], ydata = []
        dataobj.forEach(function (item, index) {
            xdata.push(item.name);
            ydata.push(item.value);
        });
        var myChart = echarts.init(document.getElementById('qcUseTime'));
        // 指定图表的配置项和数据
        var option = {
            title: {
                text: '病种填报用时平均分析',
                left: 'center'
            },
            tooltip: {},
            legend: {},
            xAxis: {
                type: 'category',
                data: xdata,
                axisLabel: {
                    interval: 0,
                    formatter: function (params) {
                        var str = "";                 // 最终拼接成的字符串
                        var paramsLen = params.length;// 获取每项文字的个数
                        var len = 5;                  // 每行能显示的字的个数（根据实际情况自己设置）
                        var rowNumber = Math.ceil(paramsLen / len); // 换行的话，需要显示几行，向上取整
                        if (paramsLen > len) {        //大于设定的len就换行，不大于就不变化
                            for (var i = 0; i < rowNumber; i++) {
                                var temp = "";            // 表示每一次截取的字符串
                                var start = i * len;      // 开始截取的位置
                                var end = start + len;    // 结束截取的位置
                                if (i == rowNumber - 1) { // 最后一次不换行
                                    temp = params.substring(start, paramsLen);
                                } else {                  // 每一次拼接字符串并换行
                                    temp = params.substring(start, end) + "\n";
                                }
                                str += temp;              // 最终拼成的字符串
                            }
                        } else {                      // 给新的字符串赋值
                            str = params;
                        }
                        return str;                   //返回字符串
                    }
                }
            },
            yAxis: {
                name: '分',
                max: 'dataMax'
            },
            series: [
                {
                    type: 'bar',
                    data: ydata,
                    barMaxWidth: '40px',
                    itemStyle: {
                        color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                            {offset: 0, color: '#83bff6'},
                            {offset: 0.5, color: '#188df0'},
                            {offset: 1, color: '#188df0'}
                        ])
                    },
                    label: {
                        show: true, // 显示标签
                        position: 'top' // 标签位置顶部
                    }
                }
            ],
            dataZoom: [{
                type:'slider',
                xAxisIndex: [0],
                start: 0,
                end:30
            }]
        };
        myChart.setOption(option);
        $("#downloadQcUseTime").on('click', function () {
            objScreen.downloadEcharts(option);
        });
    }, function (data) {
    });
    ajax.set(params);
    ajax.start();
}

objScreen.downloadEcharts = function (options, myChart, label) {
    if (myChart) {
        // 获取图表的数据 URL
        var dataURL = myChart.getDataURL({
            type: 'png',  // 可以根据需要修改为其他格式，如 'jpeg'
            pixelRatio: 2,  // 图片分辨率，根据需要进行调整
            backgroundColor: '#fff'  // 图片背景色，根据需要进行调整
        });
        // 创建一个虚拟的下载链接并模拟点击下载
        var link = document.createElement('a');
        link.href = dataURL;
        var imageName = 'echarts_image.png';
        if (options.title && options.title.text) {
            imageName = options.title.text + '.png';
        }
        link.download = imageName;  // 下载的文件名，可以根据需要修改
        link.style.display = 'none';
        link.click();
        return;
    }

    // 获取完整的数据
    const fullData = options;
    var newOption = fullData;
    newOption.dataZoom = [];
    newOption.grid = {
        containLabel: true, //注意加上，否则axisLabel有可能显示会不全
        bottom:"10px"
    };
    
    if (label) {
        newOption.series[0].label = label;
    }

    var chartDom = document.createElement('div');
    chartDom.style.width = 90 * fullData.series[0].data.length + 'px'
    chartDom.style.height = '800px'
    var newMyChart = echarts.init(chartDom);
    newMyChart.setOption(newOption);
    newMyChart.on('finished', () => {
        // 获取图表的数据 URL
        var dataURL = newMyChart.getDataURL({
            type: 'png',  // 可以根据需要修改为其他格式，如 'jpeg'
            pixelRatio: 2,  // 图片分辨率，根据需要进行调整
            backgroundColor: '#fff'  // 图片背景色，根据需要进行调整
        });
        // 创建一个虚拟的下载链接并模拟点击下载
        var link = document.createElement('a');
        link.href = dataURL;
        var imageName = 'echarts_image.png';
        if (newOption.title && newOption.title.text) {
            imageName = newOption.title.text + '.png';
        }
        link.download = imageName;  // 下载的文件名，可以根据需要修改
        link.style.display = 'none';
        link.click();
    })

};